//
//  BTEBaseNavigationViewController.swift
//  BTE
//
//  Created by Mike Zhang on 2025/8/5.
//


import UIKit

class BTEBaseNavigationViewController: UINavigationController, UIGestureRecognizerDelegate, UINavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.delegate = self
        self.setNavigationBarHidden(true, animated: false)
    }

    // 控制手势返回是否启用
    func navigationController(_ navigationController: UINavigationController,
                              willShow viewController: UIViewController,
                              animated: Bool) {
        navigationController.interactivePopGestureRecognizer?.delegate =
            (navigationController.viewControllers.count > 1) ? self : nil
    }

    // 状态栏样式交给当前的 visibleViewController
    override var childForStatusBarStyle: UIViewController? {
        return self.visibleViewController
    }

    // UIGestureRecognizerDelegate
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return self.viewControllers.count > 1
    }

    // push 时的处理
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(
                image: UIImage(named: "fewfewfwefwefew"),
                style: .plain,
                target: self,
                action: #selector(bcTapped)
            )
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func bcTapped() {
        // 自定义返回按钮点击事件
        self.popViewController(animated: true)
    }
}
